package com.gitee.es.dynamics.config;

import com.gitee.es.dynamics.aop.ElasticSearchAspect;
import com.gitee.es.dynamics.util.CoreUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;

import javax.annotation.Resource;

/**
 * 自动注入es配置
 */
@Slf4j
@Import({DynamicsElasticSearchConfig.class, ElasticSearchAspect.class})
@EnableAspectJAutoProxy
public class AutoElasticSearchConfig implements InitializingBean {
    @Resource
    private DynamicsElasticSearchConfig dynamicsElasticSearchConfig;

    /**
     * springboot所有配置加载完执行
     *
     * @return void
     * @date 2023/12/29 8:44
     * @author glq
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        if (!dynamicsElasticSearchConfig.getOpenSqlConfig()) {
            log.info("Use user yml config！");
            CoreUtil.loadCoreConfig(dynamicsElasticSearchConfig.getConfigs());
        }
    }
}
